<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>原生JS实现元素拖拽</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    #dragDiv {
      width: 100px;
      height: 100px;
      background-color: red;
      /*脱离文档流，便于拖拽时计算坐标*/
      position: fixed;
      top: 0;
      left: 0;
      /*鼠标呈拖拽状*/
      cursor: move;
    }
  </style>
</head>

<body>
<div id="dragDiv"></div>

<script src="drag.js"></script>
<script>
  // 获取到要拖拽的元素
  var dragElement = document.getElementById("dragDiv");
  drag(dragElement);
</script>

</body>
</html>
